package ch2;

import java.util.*;

import ch1.Person;

public class CollectionsMax2 {

	public static void main(String[] args) {
		List<Double> list = new ArrayList<>();
		for (int i = 1; i <= 20; i++)
			list.add(Math.random() * 1000);
		System.out.println(list);

		Double max = Collections.max(list);
		Double min = Collections.min(list);
		System.out.println("最大：" + max + ",最小：" + min);
		// String可以比较大小？
		// 可排序
		Collections.sort(list);
		System.out.println("排序后：");
		System.out.println(list);
		// 自定义对象

		List<Person> l2 = new ArrayList<>();
		l2.add(new Person("许鹏", 22, "男"));
		l2.add(new Person("徐明浩", 23, "男"));
		l2.add(new Person("蒋伟", 32, "男"));
		l2.add(new Person("谢旭", 22, "男"));
		l2.add(new Person("汪翔", 12, "男"));
		l2.add(new Person("法海", 14, "男"));
		l2.add(new Person("白素贞", 15, "男"));
		Person p = Collections.max(l2);
		System.out.println(p);
		Person p2 = Collections.min(l2);
		System.out.println(p2);

		Collections.sort(l2);
		System.out.println("排序后：");

		System.out.println(l2);

		// 必须l2是有序的，binarySearch才有意义
		int pos = Collections.binarySearch(l2, new Person("白素贞", 15, "妖"));
		if (pos == -1) {
			System.out.println("不在");
		} else {
			System.out.println("在集合的第" + (pos + 1) + "处");
		}
	}

}
